package com.education.welco.pojo.vo;

import com.education.welco.pojo.PlatformResources;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jodd.util.StringPool;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @Author: liftsail
 * @Date: 2022/9/15 14:31
 * @Description: 不积跬步无以至千里
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DirTreeNode {

    //用户文件id
    private String id;

    //用户文件名
    @JsonProperty("label")
    private String filename;

    //所在目录，根目录为null
    private String pid;

    //树深度
    private Long depth;

    //子目录
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<DirTreeNode> children;


    public static DirTreeNode root() {
        return new DirTreeNode(null, StringPool.SLASH, null, 0L, null);
    }

    public static DirTreeNode create(PlatformResources platformResources, Long depth, List<DirTreeNode> children) {
        return new DirTreeNode(platformResources.getId(), platformResources.getFileName(), platformResources.getPid(), depth, children);
    }
}
